"use strict";

const Service = require("egg").Service;

class RoomService extends Service {
    /**
     * 添加教室
     * @param {string} sn 教室号
     */
    async insert(sn) {
        let sql = "insert into room (sn) values (?)";
        let params = [sn];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }

    /**
     * 根据教室ID，查询教室
     * @param {number} id 教室id
     */
    async find(id) {
        let sql = "select * from room where id = ?";
        let params = [id];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }

    /**
     * 根据教室号查询教室
     * @param {string} sn 教室号
     */
    async selectBySn(sn) {
        let sql = "select * from room where sn = ?";
        let params = [sn];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }

    /**
     * 查询教室列表
     */
    async select() {
        let sql = "select * from room";
        let res = await this.app.mysql.query(sql);
        return res;
    }

    /**
     * 删除教室
     */
    async delete(id) {
        let sql = "delete from room where id = ?";
        let params = [id];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = RoomService;
